
pic1 = new Image(16, 16);
pic1.src = "../images/loader.gif";

$(document).ready(function(){


    $("input#Email").change(function()
    {

        var usr = $("input#Email").val();

        if(usr.length >= 4)
        {
            $("#status").html('<img src="../images/loader.gif" align="absmiddle">&nbsp;Checking availability...');

            $.ajax(
            {
                type: "POST",
                url: "regscript.php",
                data: "Email="+ usr,
                success: function(msg)
                {

                    $("#status").ajaxComplete(function(event, request, settings)
                    {

                        if(msg == 'OK')
                        {
                            $(this).html('&nbsp;<img src="../images/tick.gif" align="absmiddle">');
                        }
                        else
                        {
                            $(this).html(msg);
                        }

                    });

                }

            });

        }
        else
        {
            $("#status").html('<font color="red">The username should have at least <strong>4</strong> characters.</font>');
        }



    });

    $("input#Password").change(function()
    {

        var passw = $("input#Password").val();

        if(passw.length > 5)
        {
            $("#pstatus").html('<img src="../images/loader.gif" align="absmiddle">&nbsp;Validating...');

            $.ajax(
            {
                type: "POST",
                url: "regscript.php",
                data: "&Password="+ passw,
                success: function(msg)
                {
                    $("#pstatus").ajaxComplete(function(event, request, settings)
                    {
                        if(msg == 'OK')
                        {
                            $(this).html('&nbsp;<img src="../images/tick.gif" align="absmiddle">');
                        }
                        else
                        {
                            $(this).html(msg);
                        }

                    });

                }

            });
        }
        else
        {
            $("#pstatus").html('<font color="red">The password needs to be > <strong>5</strong> characters.</font>');
        }

        var con = $("input#confirm").val();

        if(passw != con)
        {
            $("#cstatus").html('<font color="red">Passwords are not matching');
        }

    });

    $("input#confirm").keyup(function()
    {
        var con = $("input#confirm").val();
        var real = $("input#Password").val();


        if(real != con)
        {
            $("#cstatus").html('<font color="red">Passwords are not matching</font>');
        }
        else
        {

            $.ajax(
            {
                type: "POST",
                url: "regscript.php",
                data: "&Confirm_Password="+ con,
                success: function(msg)
                {
                    $("#cstatus").ajaxComplete(function(event, request, settings)
                    {
                        if(msg == 'OK')
                        {
                            $(this).html('&nbsp;<img src="../images/tick.gif" align="absmiddle">');
                        }
                        else
                        {
                            $(this).html(msg);
                        }

                    });

                }

            });

        }


    });


    $("input#First").change(function()
    {
        var first = $("input#First").val();

        $.ajax(
        {
            type: "POST",
            url: "regscript.php",
            data: "&First="+ first,
            success: function(msg)
            {

                $("#fstatus").ajaxComplete(function(event, request, settings)
                {

                    if(msg == 'OK')
                    {
                        $(this).html('&nbsp;<img src="../images/tick.gif" align="absmiddle">');
                    }
                    else
                    {
                        $(this).html(msg);
                    }

                });

            }

        });

    });


    $("input#Last").change(function()
    {
        var last = $("input#Last").val();

        $.ajax(
        {
            type: "POST",
            url: "regscript.php",
            data: "&Last="+ last,
            success: function(msg)
            {

                $("#lstatus").ajaxComplete(function(event, request, settings)
                {

                    if(msg == 'OK')
                    {
                        $(this).html('&nbsp;<img src="../images/tick.gif" align="absmiddle">');
                    }
                    else
                    {
                        $(this).html(msg);
                    }

                });

            }

        });

    });


    $("input#Zip").keyup(function()
    {

        var zip = $("input#Zip").val();

        if(zip.length >= 3)
        {
            $("#phstatus").html('<img src="../images/loader.gif" align="absmiddle">&nbsp;Validating');

            $.ajax(
            {
                type: "POST",
                url: "regscript.php",
                data: "&Zip="+ zip,
                success: function(msg)
                {

                    $("#phstatus").ajaxComplete(function(event, request, settings)
                    {

                        if(msg == 'OK')
                        {
                            $(this).html('&nbsp;<img src="../images/tick.gif" align="absmiddle">');
                        }
                        else
                        {
                            $(this).html(msg);
                        }

                    });

                }

            });

        }
        else
        {
            $("#phstatus").html('<font color="red">Not enough digits in the phone number</font>');
        }



    });


     $("input#Firstp").keyup(function()
    {

        var firstp = $("input#Firstp").val();

        if(firstp.length >= 3)
        {
            $("#phstatus").html('<img src="../images/loader.gif" align="absmiddle">&nbsp;Validating');

            $.ajax(
            {
                type: "POST",
                url: "regscript.php",
                data: "&Firstp="+ firstp,
                success: function(msg)
                {

                    $("#phstatus").ajaxComplete(function(event, request, settings)
                    {

                        if(msg == 'OK')
                        {
                            $(this).html('&nbsp;<img src="../images/tick.gif" align="absmiddle">');
                        }
                        else
                        {
                            $(this).html(msg);
                        }

                    });

                }

            });

        }
        else
        {
            $("#phstatus").html('<font color="red">Not enough digits in the phone number</font>');
        }



    });


    $("input#Lastp").keyup(function()
    {

        var lastp = $("input#Lastp").val();

        if(lastp.length >= 4)
        {
            $("#phstatus").html('<img src="../images/loader.gif" align="absmiddle">&nbsp;Validating');

            $.ajax(
            {
                type: "POST",
                url: "regscript.php",
                data: "&Lastp="+ lastp,
                success: function(msg)
                {

                    $("#phstatus").ajaxComplete(function(event, request, settings)
                    {

                        if(msg == 'OK')
                        {
                            $(this).html('&nbsp;<img src="../images/tick.gif" align="absmiddle">');
                        }
                        else
                        {
                            $(this).html(msg);
                        }

                    });

                }

            });

        }
        else
        {
            $("#phstatus").html('<font color="red">Not enough digits in the phone number</font>');
        }



    });

});


